%%%-------------------------------------------------------------------
%%% File    : rdf_record.erl
%%% Author  :  <vjache>
%%% Description : 
%%%
%%% Created :  2 May 2009 by  <vjache>
%%%-------------------------------------------------------------------
-module(rdf_record).

-include("../include/rdf_record.hrl"). 

%% API
-export([
		 tuple_to_spog/1,
		 to_norm/1,
		 as_spog/1,
		 as_psog/1,
		 as_ospg/1,
		 as_gspo/1,
		 as/2,
		 from_norm/2,
		 tag_by_role/1,
		 role_pos/1
		 ]).

%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: 
%% Description:
%%--------------------------------------------------------------------
tuple_to_spog({S,P,O}) ->
	tuple_to_spog({S,P,O,'_'});
tuple_to_spog({S,P,O,G}) ->
	?SPOG.

as_spog(Quad)->
	as(?SPOG_TAG,Quad).
as_psog(Quad)->
	as(?PSOG_TAG,Quad).
as_ospg(Quad)->
	as(?OSPG_TAG,Quad).
as_gspo(Quad)->
	as(?GSPO_TAG,Quad).
%%====================================================================
%% Internal functions
%%====================================================================
as(Tag,Quad) ->
	from_norm(to_norm(Quad),Tag).

tag_by_role(s) ->
	?SPOG_TAG;
tag_by_role(p) ->
	?PSOG_TAG;
tag_by_role(o) ->
	?OSPG_TAG;
tag_by_role(g) ->
	?GSPO_TAG.

role_pos(s) -> 1;
role_pos(p) -> 2;
role_pos(o) -> 3;
role_pos(g) -> 4.


to_norm(?SPOG=Q) ->
	Q;
to_norm(?PSOG) ->
	?SPOG;
to_norm(?OSPG) ->
	?SPOG;
to_norm(?GSPO) ->
	?SPOG.


from_norm(?SPOG=Q,?SPOG_TAG) ->
	Q;
from_norm(?SPOG,?PSOG_TAG) ->
	?PSOG;
from_norm(?SPOG,?OSPG_TAG) ->
	?OSPG;
from_norm(?SPOG,?GSPO_TAG) ->
	?GSPO.




